package com.example.zqathserver.controller;

import cn.hutool.json.JSONUtil;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;


/**
 * 盈峰H5登录接口
 * SIAM TGT验证接口控制器
 * 模拟返回指定的JSON响应格式
 */
@RestController
@RequestMapping("siam/rest/auth")
public class YFJTHController {

    /**
     * TGT验证接口
     * 直接返回指定的JSON格式响应
     */
    @PostMapping("/validate")
    public Map<String, Object> validateTicket(@RequestBody(required = false) Map<String, Object> requestBody, HttpServletRequest request) {
        // 打印接收到的请求信息（用于调试）
        System.out.println("收到TGT验证请求");
        System.out.println("请求头-AppUser: " + request.getHeader("appuser"));
        System.out.println("请求头-RandomCode: " + request.getHeader("randomcode"));
        System.out.println("请求头-Timestamp: " + request.getHeader("timestamp"));
        System.out.println("请求头-EncodeKey: " + request.getHeader("encodekey"));
        System.out.println("请求头-Sign: " + request.getHeader("sign"));

        if (requestBody != null) {
            System.out.println("请求体: " + JSONUtil.toJsonStr(requestBody));
        }

        // 构建响应数据
        Map<String, Object> response = new HashMap<>();
        response.put("qrNum", null);
        response.put("success", "true");
        response.put("resultCode", 1);
        response.put("message", "The ticket is valid!");
        response.put("ticketEntry", null);

        // 构建用户信息
        Map<String, Object> userInfo = new HashMap<>();
        userInfo.put("uid", "super");
        userInfo.put("smart-account-sec-conf", "spso");
        response.put("user", userInfo);

        return response;
    }
}